package com.itcast.demoone

import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class PageTwoActivity : AppCompatActivity() {

    // 定义一个常量
    private val TAG = "itHeiMa-B"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Log.d(TAG, "onCreate-B页面")

        enableEdgeToEdge()
        setContentView(R.layout.activity_page_two)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 接收上一个页面传递的数据
        val name = intent.getStringExtra("name")
        val age = intent.getIntExtra("age", 0)
        Toast.makeText(this, "name: $name, age: $age", Toast.LENGTH_SHORT).show()

        val backBtn = findViewById<Button>(R.id.btn_back)
        backBtn.setOnClickListener {
            finish()
        }
    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart-B页面")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume-B页面")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause-B页面")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop-B页面")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy-B页面")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(TAG, "onRestart-B页面")
    }
}